package Demo;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: hp
 * Date: 2024-03-25
 * Time: 23:17
 */
public class Cards {
    private static final String suits[] = {"♥","♠","♣","♦"};
    public List<Card> buyCard() {
        List<Card> cardList = new ArrayList<>();
        for(int i = 0; i < 4; i++) {
            for (int j = 1; j <= 13; j++) {
                Card card = new Card(j,suits[i]);
                cardList.add(card);
            }
        }
        return cardList;
    }

    public void shuffle(List<Card> cardList) {
        Random random = new Random();
        for (int i = cardList.size() - 1; i > 0 ; i--) {
            int rand = random.nextInt(i);
            swap(cardList,i,rand);
        }
    }

    private void swap(List<Card> cardList,int i,int j) {
        Card tmpCard = cardList.get(i);
        cardList.set(i,cardList.get(j));
        cardList.set(j,tmpCard);
    }


    public void faPai(List<Card> cardList) {
        List<Card> hand1 = new ArrayList<>();
        List<Card> hand2 = new ArrayList<>();
        List<Card> hand3 = new ArrayList<>();

        List<List<Card>> hands = new ArrayList<>();
        hands.add(hand1);
        hands.add(hand2);
        hands.add(hand3);
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 3; j++) {
                Card card = cardList.remove(0);
                List<Card> cardTmp = hands.get(j);
                cardTmp.add(card);
            }
        }

        System.out.println("第一个人的牌" + hand1);
        System.out.println("第二个人的牌" + hand2);
        System.out.println("第三个人的牌" + hand3);
    }



}
